package com.ccsoft.atools.utils;

import lombok.ToString;

/**
 * @ClassName:JsonResult
 * @Description:TODO
 * @Author:chanchaw
 * @Date:2019-12-07 19:38
 * @Version:1.0
 **/
@ToString
public class JsonResult {
    private Integer code;
    private String msg;
    private Object data;

    public JsonResult(ResultCode resultCode, Object data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public JsonResult() {
        this.code = 1;
        this.msg = "成功";
        this.data = null;
    }

    public JsonResult(String msg) {
        this.code = 1;
        this.msg = msg;
        this.data = null;
    }

    public JsonResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }


    public static JsonResult ok() {
        return new JsonResult();
    }

    public static JsonResult ok(Object data) {
        return new JsonResult(ResultCode.OK, data);
    }

    public static JsonResult error(ResultCode resultCode) {
        return new JsonResult(resultCode, null);
    }

    public static JsonResult error(String msg) {
        return new JsonResult(7777, msg);
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public Object getData() {
        return this.data;
    }
}
